import nonebot,os
import json
from nonebot import on_command, CommandSession
from nonebot.typing import Context_T
import nonebot,os
import datetime
from nonebot.typing import Context_T
bot = nonebot.get_bot()
@bot.on_message()
async def s(ctx:Context_T):
    hour=datetime.datetime.now().hour
    day=datetime.datetime.now().day
    month=datetime.datetime.now().month
    if ctx['message_type']=='private':
        msg:Message=ctx['message'][0]
        if msg.type=='location':
            qq= str(ctx['sender']['user_id'])
            f=open("C:\\awesome-bot\\write_data.txt",encoding='utf-8')
            m=eval(f.read())
            f.close()
            f2=open("C:\\awesome-bot\\awesome\\plugins\\loc_log\\"+str(month)+"."+str(day)+".txt",'a+')
            size = os.path.getsize("C:\\awesome-bot\\awesome\\plugins\\loc_log\\"+str(month)+"."+str(day)+".txt")
            if (size==0):
                p=[]
            else:
                f2.seek(0)
                p=eval(f2.read())
                f2.close()
            if ctx['sender']['user_id'] in p:
                await bot.send_private_msg(user_id=ctx['sender']['user_id'],message="你今天已经发送过位置了！")
            else:
                with open("C:\\awesome-bot\\awesome\\plugins\\loc_log\\"+str(month)+"."+str(day)+".txt",'a') as f:
                    f.write(str(qq)+',')
                f.close()
                with open("C:\\awesome-bot\\awesome\\plugins\\loc_log\\"+str(month)+"."+str(day)+"time"+".txt",'a') as f3:
                    f3.write(m[qq]+"     "+str(datetime.datetime.now().strftime("%m-%d %H:%M:%S"))+"     "+msg.data['content']+'\n')
                f3.close()
                await bot.send_private_msg(user_id=ctx['sender']['user_id'],message="录入成功")
            if len(p)==31:
                f4=open("C:\\awesome-bot\\awesome\\plugins\\loc_log\\"+str(month)+"."+str(day)+"time"+".txt")
                loca=f4.read()
                print("位置信息统计完毕")
                await bot.send_private_msg(user_id=1924370941,message="位置信息统计完毕，如下：\n"+str(loca))

@on_command('打卡')
async def daka(session: CommandSession):
    num = session.get('num', prompt='一.是否存在以下行为，如果均未出现请回复（否），否则回复序号！\n\n1、身体状况异常\n2、是否外出实习\n3、离开现居地\n4、从外地返青、从湖北疫区外出、从外省去湖北疫区、从国外回国')
    num2 = session.get('num2', prompt='二.请发送位置信息完成打卡！')
    msg:Message=session.ctx['message'][0]
    #print(num2,type(num2))
    #print(msg,type(msg))
    if msg.type=='location':
        print(msg.data['content'])
        await session.send("打卡成功")
    else:
        await session.send("shibai")
